import datetime
import time


class TimeManager(object):
    """
    时间管理器
    """

    @staticmethod
    def get_time_stamp():
        """
        获取本地时间戳
        :return:
        """
        return time.time()

    @staticmethod
    def str_time_to_float_time(time_str, format_str):
        """
        字符串转浮点值
        :param time_str:
        :param format_str:
        :return:
        """
        return time.mktime(time.strptime(time_str, format_str))

    @staticmethod
    def float_time_to_str_time(time_float, format_str):
        """
        浮点值转字符串
        :param time_float:
        :param format_str:
        :return:
        """
        return time.strftime(format_str, time.localtime(time_float))


if __name__ == '__main__':
    str_format = "%Y-%m-%d %H:%M:%S"
    time_manager = TimeManager()
    time_int = time.time()
    str_time = time_manager.float_time_to_str_time(time_int, str_format)
    print(str_time)

# # 获取本地gmt时间
# gmt = time.gmtime()
#
# # 获取本地时间
# local = time.localtime()
#
# # 本地时间格式化
# strtime = time.ctime()
#
# # 结构化时间转换成格式化字符
# asctime = time.asctime()
#
# # 将结构化时间转换成时间戳
# constamp = time.mktime(local)
#
# # 将结构化时间转换成指定字符串格式时间
# # strf = time.strftime("%Y-%m-%d %H:%M:%S")
# strf = time.strftime("%Y/%m/%d %H:%M:%S")
#
# # 将格式化时间转成结构化时间
# struct_time = time.strptime("2021-10-29 21:07:24", "%Y-%m-%d %H:%M:%S")
# print("获取本地gmt时间:", gmt)
# print("获取本地时间:", local)
# print("本地时间格式化:", strtime)
# print("结构化时间转换成格式化字符:", asctime)
# print("将结构化时间转换成时间戳:", constamp)
# print("将结构化时间转换成指定字符串格式时间:", strf)
# print("将格式化时间转成结构化时间:", struct_time)
